/*
 * CheckUserexistsService.java
 *
 * Created on 15 March 2006, 15:07
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package ajax.services;

import ajax.AjaxController;
import java.io.PrintWriter;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import web.ApplicationController;
import web.services.Service;
import web.util.BusinessFacadeDelegate;

/**
 *
 * @author Phil
 */
public class CheckUserexistsService extends CheckService{
    public static final String USER_EMAILS = "emails";
    public static final String PARTICIPANT_TYPE = "type";
    
    public CheckUserexistsService() {
    }
    
    public String executePreDispatch(HttpServletRequest request,
            ServletContext context) throws Exception {
        return "display";        
    }
    
    public void executeDispatch(HttpServletRequest request,
            ServletContext context,
            PrintWriter out){
        String emails = request.getParameter(USER_EMAILS);
        String muid = request.getParameter(Service.MEETING_ID);        
        BusinessFacadeDelegate delegate = ((BusinessFacadeDelegate)request.getSession().getAttribute(ApplicationController.BUSINESS_DELEGATE_REF));
        String response = "type=" + request.getParameter(PARTICIPANT_TYPE) + "\n";
        String[] users = emails.split(",");
        for(int i=0; i<users.length;i++){
            users[i].trim();
            response+=users[i]+","+delegate.checkUserExists(users[i], muid) +"\n";
        }
        response = response.substring(0, response.length()-1);
        out.print(response);
    }
    
    public void executePostDispatch(HttpServletRequest request,
            ServletContext context)throws Exception{
        
    }
    
}
